package com.gitee.magic.framework.head.converter;

import java.text.SimpleDateFormat;

import com.gitee.magic.core.converter.AbstractConverterEditor;
import com.gitee.magic.core.converter.DocDescription;
import com.gitee.magic.framework.head.utils.TimeUtils;

/**
 * @author start
 */
@DocDescription(TimeUtils.YYYYMMDD)
public class DateConverterEditor extends AbstractConverterEditor<String>  {
	
	public DateConverterEditor(Class<?> prototype) {
		super(prototype);
	}

	@Override
	public void restore(Object value) {
		if(value!=null) {
			setValue(DateTimeConverterEditor.restoreValue(value,TimeUtils.YYYYMMDD));
		}
	}

	@Override
	public String converter() {
		if(getValue()==null) {
			return null;
		}
		SimpleDateFormat sd = new SimpleDateFormat(TimeUtils.YYYYMMDD);
		return sd.format(getValue());
	}

	@Override
	public Object getSource() {
		return converter();
	}
	
}
